package model.beans;

import core.OrderQueue;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import model.user.UserSessionBean;

/**
 *
 * @author Danon
 */
@ManagedBean
@RequestScoped
public class OrderBean {

    private int id;
    private String orderDate;
    private String completionDate;
    private String status;
    private float bandwidth;
    private String comment;
    private int userId;
    private String sourceRouterName;
    private String destinationRouterName;

    public String getDestinationRouterName() {
        return destinationRouterName;
    }

    public void setDestinationRouterName(String destinationRouterName) {
        this.destinationRouterName = destinationRouterName;
    }

    public String getSourceRouterName() {
        return sourceRouterName;
    }

    public void setSourceRouterName(String sourceRouterName) {
        this.sourceRouterName = sourceRouterName;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }
    
    /** Creates a new instance of OrderBean */
    public OrderBean() {
        orderDate = new SimpleDateFormat("dd.MM.yyyy").format(new Date());
        bandwidth = 1024;
    }

    public float getBandwidth() {
        return bandwidth;
    }

    public void setBandwidth(float bandwidth) {
        this.bandwidth = bandwidth;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getOrderDate() {
        return orderDate;
    }

    public void setOrderDate(String orderDate) {
        this.orderDate = orderDate;
    }

    public String getStatus() {
        return status;
    }
    
    public void setStatus(String status) {
        this.status = status;
    }

    public String getCompletionDate() {
        return completionDate;
    }

    public void setCompletionDate(String completionDate) {
        this.completionDate = completionDate;
    }
    
    @Override
    public String toString() {
        return getId() + " " + getOrderDate()+" " +getSourceRouterName() + " " + getDestinationRouterName() + " " + getBandwidth() + " " + getStatus() + " // "+getComment();
    }
    
    public String makeOrder(UserSessionBean session) {
        this.setUserId(session.getUser().getId());
        OrderQueue.getInstance().newOrder(this);
        return "welcome?faces-redirect=true";
    }
}
